package GUI;

import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.Dialog.ModalityType;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.AbstractButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;

public class WaiterDialog {
	public static boolean stop;
	public static Window window;
	public static JDialog dialog;
	
	public static void stop(){
		stop=true;
	}
	public static void show(Window win){
		window=win;
		stop=false;
	     SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>(){
	         @Override
	         protected Void doInBackground() throws Exception {

		   	      JProgressBar progressBar = new JProgressBar();
			      progressBar.setIndeterminate(true);
			      JPanel panel = new JPanel(new BorderLayout());
			      panel.add(progressBar, BorderLayout.CENTER);
			      panel.add(new JLabel("Please wait......."), BorderLayout.PAGE_START);
			      dialog = new JDialog(window, "Dialog", ModalityType.APPLICATION_MODAL);
			      dialog.add(panel);
			      dialog.pack();
			      dialog.setLocationRelativeTo(window);
			      dialog.setVisible(true);
	        	while (true){
		            Thread.sleep(200);
	        		if(stop){
		                  dialog.dispose();
	        			break;
	        		}
	        	}
	            return null;
	         }
	      };


			

	      mySwingWorker.execute();

	}
	
}
